﻿using AntdUI;
using BST250301TestStand.Models.Utils;
using Google.Protobuf.WellKnownTypes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BST250301TestStand.Models
{
    internal class AlarmItem
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Code { get; set; }
        public string Desccription { get; set; }
        public string ByEQ { get; set; }
        public int ResetState { get; set; }
        public DateTime DTAlmarm { get; set; }
        public AlarmEnum Level { get; set; }
        public DateTime DTCreate { get; set; }
    }
    internal class RemoteItem
    {
        public string Name { get; set; }
        public string Addr { get; set; }
        public string Value { get; set; }
    }
    internal class GroupItem
    {
        public int ID { get; set; }
        public string GroupName { get; set; }
        public string Description { get; set; }
        public string Author { get; set; }
        public string Code { get; set; }
        public string Note { get; set; }
    }

    /// <summary>
    /// 项目类
    /// </summary>
    [Serializable]
    public class ProjectItem
    {
        /// <summary>
        /// 是否选中
        /// 程序运行时判断，其他不理会
        /// </summary>
        public bool IsChecked { get; set; }
        public ProType ItemType { get; set; } = ProType.标准程序;
        /// <summary>
        /// 人工确认当前工序是否正常
        /// 避免飞车/损毁设备
        /// </summary>
        public ConfWay ConfirmWay { get; set; } = ConfWay.手动确认;
        /// <summary>
        /// 当前工序进度
        /// </summary>
        public int Processing { get; set; }
        /// <summary>
        /// 顺序号
        /// </summary>
        public int OrderID { get; set; }
        /// <summary>
        /// 记录id
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// 工序名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 模板名称，不是项目名称
        /// </summary>
        public string TemplateName { get; set; }
        /// <summary>
        /// 方案名称
        /// </summary>
        public string PlanName { get; set; }
        
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }
        /// <summary>
        /// guid号，避免重复
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 设置用户
        /// </summary>
        public string Mark { get; set; }
        /// <summary>
        /// 油温
        /// </summary>
        public TOil TemperatureOil { get; set; }
        /// <summary>
        /// 离合器CF
        /// </summary>
        public ClutchStatus CFStatus { get; set; } = ClutchStatus.断开;
        /// <summary>
        /// 离合器CR
        /// </summary>
        public ClutchStatus CRStatus { get; set; } = ClutchStatus.断开;
        /// <summary>
        /// 离合器CPTO
        /// </summary>
        public ClutchStatus CPTOStatus { get; set; } = ClutchStatus.断开;
        /// <summary>
        /// 主档位置
        /// </summary>
        public GearM MasterGearPosition { get; set; }
        /// <summary>
        /// 副档位置
        /// </summary>
        public GearS SlaveGearPosition { get; set; }
        /// <summary>
        /// PTO挡位
        /// </summary>
        public GearPTO PTOGearPosition { get; set; }
        /// <summary>
        /// 转速
        /// </summary>
        public StepTest RotateSpeed { get; set; }
        /// <summary>
        /// 负载扭矩 值为50代表50%即给plc发送0.50
        /// </summary>
        public float LoadTorque { get; set; }
        /// <summary>
        /// CF设置电流
        /// </summary>
        public StepTest CFSetPointCurrent { get; set; }
        /// <summary>
        /// CR设置电流
        /// </summary>
        public StepTest CRSetPointCurrent { get; set; }
        /// <summary>
        /// CPTO设置电流
        /// </summary>
        public StepTest CPTOSetPointCurrent { get; set; }
        /// <summary>
        /// 公共阶跃设置（KP测试时增加的）
        /// </summary>
        public StepTest SetPointCurrentKP { get; set; }
       
        /// <summary>
        /// 测试条件
        /// </summary>
        public string TestCondition { get; set; }
        /// <summary>
        /// 前置延时s
        /// </summary>
        public int PreDelay { get; set; }
        /// <summary>
        /// 测试区间时长s
        /// </summary>
        public int TestDuration { get; set; }
        /// <summary>
        /// 后置延时s
        /// </summary>
        public int AfterDelay { get; set; }
        /// <summary>
        /// 记录数据List<name>，便于数据库存取用
        /// 不为空代表有记录数据要求
        /// </summary>
        public List<string> ListRecordData { get; set; }
        /// <summary>
        /// 记录数据List<RecordData类>
        /// </summary>
        public List<RecordData> ListRecord { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Note { get; set; }
        /// <summary>
        /// 产品SN
        /// </summary>
        public string SN { get; set; }
        /// <summary>
        /// 是否队列中的第一个执行的子项
        /// 用于判断是否提示换挡操作
        /// </summary>
        public bool IsListFirst { get; set; }
        /// <summary>
        /// 本项目循环测试次数
        /// </summary>
        public int Times { get; set; } = 1;
        /// <summary>
        /// 阶跃测试记录数据
        /// </summary>
        public List<ShowDataRecord> ListShowRealData { get; set; } = new List<ShowDataRecord>(); 
        /// <summary>
        /// 转换的低通滤波数据
        /// </summary>
        public List<ShowDataRecord> ListShowRealDataFilter { get; set; } = new List<ShowDataRecord>();
        /// <summary>
        /// 该项目合格标志
        /// </summary>
        public bool IsItemOKNG { get; set; }

        /// <summary>
        /// 编辑列表时用的选中按钮
        /// </summary>
        public CellLink[] CellLinks { get; set; } = new CellLink[]{
                    new CellButton("","选中",TTypeMini.Primary),
            };
    }

    /// <summary>
    /// 阶跃测试
    /// </summary>
    public class StepTest
    {
        /// <summary>
        /// TCU/PLC/NVH?
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 设置起步值
        /// </summary>
        public int ValueStart { get; set; }
        /// <summary>
        /// 设置峰值
        /// </summary>
        public int ValueEnd { get; set; }
        /// <summary>
        /// 每步阶跃值/起始时长
        /// </summary>
        public int StepValue { get; set; }
        /// <summary>
        /// 每阶跃保持时长（秒）/峰值时长
        /// </summary>
        public int StepKeep { get; set; }
        /// <summary>
        /// 重复次数
        /// </summary>
        public int Repeat { get; set; }
        /// <summary>
        /// 是否阶跃
        /// </summary>
        public bool IsStep { get; set; }
        /// <summary>
        /// 电流控制模式
        /// 0为普通模式，1为电流阶跃控制模式，2为电流脉冲控制模式
        /// </summary>
        public int SPCMode { get; set; }
        /// <summary>
        /// KP测试时启动时长
        /// </summary>
        public int KPStartKeep { get; set; }
        /// <summary>
        /// KP测试时结束时长
        /// </summary>
        public int KPEndKeep { get; set; }
        /// <summary>
        /// KP测试时最大输出轴转速//后改最达输入轴转速
        /// </summary>
        public float KPMaxOutSpeed { get; set; }
        /// <summary>
        /// 到达设定值输入轴速度时的压力
        /// </summary>
        public float KPMaxPressure { get; set; }
        /// <summary>
        /// KP测试达到设定值速度的平均压力
        /// </summary>
        public float KPMaxAVGPressure { get; set; }

    }
    internal class TemplateItem
    {
        public int OrderID { get; set; }
        public ProType ItemType { get; set; } = ProType.标准程序;
        public string UserId { get; set; }
        public int Repeat { get; set; }
        /// <summary>
        /// 方案名称
        /// </summary>
        public string PlanName { get; set; }
        /// <summary>
        /// TemplateName子方案模板名称，不是项目 
        /// </summary>
        public string TestName { get; set; }
        /// <summary>
        /// 测试具体项目
        /// </summary>
        public string ProjectName { get; set; }
        public string ProjectCode { get; set; }
        public string Description { get; set; }
        public string StepCode { get; set; }
        public string RecordData { get; set; }
        public DateTime DT { get; set; }
        public ConfWay ConfirmWay { get; set; }
        public int PreDelay { get; set; }
        public int AfterDelay { get; set; }
    }

    /// <summary>
    /// 油温度
    /// </summary>
    public enum TOil
    {
        常温,
        t40_3,
        t40_5,
        t80_3,
        t80_5,
        异常
    }

    /// <summary>
    /// Clutch Flywheel
    /// 飞轮离合器状态
    /// </summary>
    public enum ClutchStatus
    {
        吸合,
        断开,
        电流控制
    }

    public enum GearM
    {
        N,
        档1,
        档2,
        档3,
        档4,
    }
    public enum GearS
    {
        N,
        L,
        M,        
        H,
        常啮合,
    }
    public enum GearPTO
    {
        N,
        L,      
        H,
    }

    public enum ConfWay
    {
        手动确认,
        自动确认,
    }
    public enum ProType
    {
        不处理,
        标准程序,
        前置延时,
        后置延时,
        数据统计,
    }
    public enum AlarmEnum
    {
        紧急警报,
        一般警报,
        警告信息,
    }
    /// <summary>
    /// R:0x02 N:0x03 F:0x04 三个状态
    /// </summary>
    public enum ClutcCFCR
    {
        R=0x02,
        N=0x03,
        F=0x04
    }
    /// <summary>
    /// 电磁阀电流通道
    /// </summary>
    public enum CurrentChannel
    {
        None =0x00,
        CF = 0x01,
        CR = 0x02,
        CPTO = 0x04,
        CPTOCF = 0x05,
        CPTOCR = 0x06
    }
}
